package end.controller;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.comet4j.core.CometContext;
import org.comet4j.core.CometEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import end.bean.Announcement;
import end.constant.Const;
import end.ser.AnnouncementSER;

/**
 * 
 * AlbumController.java 2016-6-27
 * 
 * Copyright zhaocj Inc. All rights reserved. Love Me Like Love Justin Bieber
 */
@Controller
@RequestMapping("/announcement/")
public class AnnouncementForController {
	private final static Logger logger = LogManager
			.getLogger(AnnouncementForController.class);

	@Autowired
	private AnnouncementSER<Announcement> announcementSER;

	public AnnouncementSER<Announcement> getAnnouncementSER() {
		return announcementSER;
	}

	public void setAnnouncementSER(AnnouncementSER<Announcement> announcementSER) {
		this.announcementSER = announcementSER;
	}

	@RequestMapping("insertAnnouncement")
	public @ResponseBody
	boolean insertAnnouncement(Announcement announcement) throws Exception {
		announcement.setUrl("javascript:;");
		announcementSER.insert(announcement);
		CometEngine engine = CometContext.getInstance().getEngine();
		engine.sendToAll(Const.COMET_CHANNEL_ANNOUNCES_STATUS, "change");
		engine.sendToAll(Const.COMET_CHANNEL_SERVER_FLAG, "1");
		return false;
	}
}
